// $Id: loggernetworkthruput.cpp 59 2004-10-20 16:47:30Z hansemil $
#include "loggernetworkthruput.h"
#include "loghandler.h"
#include "filehandler.h"
#include "file.h"
#include "node.h"
#include <iostream>
#include <list>
#include <vector>
using namespace std;

/**
 * @todo Write documentation
 */
LoggerNetworkThruput::LoggerNetworkThruput()
	: m_eos(0), transferedKiloBytesPerSecond(0)
{
	LogHandler::getInstance()->addLogger(this, "network_transfer");
	LogHandler::getInstance()->addLogger(this, "clock_tick");
}

/**
 * Opens file for writing and stores the Eos pointer
 */
void LoggerNetworkThruput::eos_simulate_start(void *eos)
{
	openFile(&m_fout, "networkthruput.csv");
	m_fout << "Time Step, kB/s" << endl;

	m_eos = (Eos *)eos;
}

/**
 * Closes file
 */
void LoggerNetworkThruput::eos_simulate_stop(void *eos)
{
	m_fout.close();
}

/**
 * @todo Describe this...
 */
void LoggerNetworkThruput::network_transfer(void *sender, void *transfer, unsigned int bytesSent)
{
	transferedKiloBytesPerSecond += ((double)bytesSent/Clock::m_secondsPerTimeStep/1024);
}

/**
 * Generates and writes the statistics for each tick
 */
void LoggerNetworkThruput::clock_tick(unsigned int time)
{
	// Write time step
	m_fout << time;

	// Write statistics
	m_fout << "," << transferedKiloBytesPerSecond;

	// Write end
	m_fout << endl;

	// Reset data
	transferedKiloBytesPerSecond = 0;
}
